package com.puntodonna.fogliocassa.client.app.presenter.main;

import com.gwtplatform.mvp.client.ViewImpl;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.inject.Inject;

public class MainView extends ViewImpl implements MainPresenter.MyView {

	private final Widget widget;

	public interface Binder extends UiBinder<Widget, MainView> {
	}

	@UiField
	protected DockLayoutPanel widgetArea;
	
	@UiField
	protected DockLayoutPanel headerArea;

	@Inject
	public MainView(final Binder binder) {
		widget = binder.createAndBindUi(this);
	}

	@Override
	public Widget asWidget() {
		return widget;
	}

	@Override
	public void setInSlot(Object slot, Widget content) {
		if (slot == MainPresenter.TYPE_WIDGET_AREA) {
			setMainContent(content);
		} else if (slot == MainPresenter.TYPE_HEADER_AREA) {
			setHeaderContent(content);
		} else {
			super.setInSlot(slot, content);
		}
	}

	public DockLayoutPanel getWidgetArea() {
		return widgetArea;
	}
	
	public DockLayoutPanel getHeaderArea() {
		return headerArea;
	}

	protected void setMainContent(Widget content) {
		getWidgetArea().clear();

		if (content != null) {
			getWidgetArea().add(content);
		}
	}

	protected void setHeaderContent(Widget content) {
		getHeaderArea().clear();

		if (content != null) {
			getHeaderArea().add(content);
		}
	}
}
